#include"at89x52.h"
unsigned char a[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char x=0;
unsigned char y=0;
void KeyScan(void)
{
    unsigned char keydata;
    P2=0XF0; // Low 4bit output 0; high 4 bit check 
    keydata=P2;
    if (keydata == 0xf0)
    {
    }
    else
    {
        if (keydata == 0xe0)
        {
            x=0;
        }
        else if(keydata == 0xd0)
        {
            x=1;
        }
        else if(keydata == 0xb0)
        {
            x=2;
        }
        else if(keydata == 0x70)
        {
            x=3;
        }
        P2=0X0F;
        keydata=P2;
        if (keydata==0x0e)
        {
            y=0;
        }
        else if (keydata==0x0d)
        {
            y=1;
        }
        else if (keydata==0x0b)
        {
            y=2;
        } 
        else if (keydata==0x07)
        {
             y=3;
        }
        P0=a[x+4*y];
    }
}

void main(void)
{

    P1=0xfe;  
    P0=a[2];



    while(1)
    {
        KeyScan();
    }
}